$(function () {
  var win_width =
    window.innerWidth ||
    document.documentElement.clientWidth ||
    document.body.clientWidth,
    win_height =
      window.innerHeight ||
      document.documentElement.clientHeight ||
      document.body.clientHeight

  if (win_width >= 979) {
    pc()
  } else {
    mobile()
  }

  function pc() {
    var mySwiper1 = new Swiper(".swiper-history", {
      loop: true,
      effect: "fade",
      fade: {
        crossFade: true
      },
      prevButton: ".swiper-button-prev-history",
      nextButton: ".swiper-button-next-history",
      slidesPerView: 3,
      initialSlide: 4,
      spaceBetween: 20,
      autoplayDisableOnInteraction: false,
      onSlideChangeStart: function (swiper) {
        $(".history .history-list li")
          .eq(swiper.realIndex)
          .addClass("active")
          .siblings()
          .removeClass("active")
      }
    })
    $(".history .history-list li").on("mouseenter", function () {
      mySwiper1.slideTo($(this).index() + 1)
    })


    var mySwiper = new Swiper(".swiper-gallery", {
      loop: true,
      prevButton: ".swiper-button-prev",
      nextButton: ".swiper-button-next",
      autoplay: 2000,
      slidesPerView: 3,
      spaceBetween: 70,
      autoplayDisableOnInteraction: false
    })

    let swiperContainer = document.querySelector('.swiper-gallery');

    swiperContainer.addEventListener('mouseenter', function () {
      mySwiper.stopAutoplay(); // 鼠标悬浮时停止自动轮播
    });

    swiperContainer.addEventListener('mouseleave', function () {
      mySwiper.startAutoplay(); // 鼠标离开时恢复自动轮播
    });

    $(".team .section_body .swiper-slide").hover(function () {
      $(this).find(".info-box .caption").fadeIn(1000);
    }, function () {
      $(this).find(".info-box .caption").fadeOut(1000);
    })

  }


  function mobile() {
    var mySwiper = new Swiper(".swiper-gallery", {
      prevButton: ".swiper-button-prev",
      nextButton: ".swiper-button-next",
      // autoplay: 2000,
      // freeMode: true,
      loop: true,
      slidesPerView: "auto",
      spaceBetween: 0,
      pagination: ".swiper-pagination-gallery",
      // autoplayDisableOnInteraction: true
    })

    let swiperContainer = document.querySelector('.swiper-gallery');

    swiperContainer.addEventListener('mouseenter', function () {
      mySwiper.stopAutoplay(); // 鼠标悬浮时停止自动轮播
    });

    swiperContainer.addEventListener('mouseleave', function () {
      mySwiper.startAutoplay(); // 鼠标离开时恢复自动轮播
    });

    $(".team .section_body .swiper-slide").hover(function () {
      $(this).find(".info-box .caption").fadeIn(1000);
    }, function () {
      $(this).find(".info-box .caption").fadeOut(1000);
    })
  }




  //动态数字
  var numFalg = false
  var triggerNumber = function triggerNumber() {
    if (numFalg) return
    var top = $(".achievement").offset().top
    if ($(window).height() / 2 + 120 + $(document).scrollTop() >= top) {
      numFalg = true
      $(".add-number").each(function () {
        var num = parseInt($(this).find("span").attr("data-num"))
        if (num == 24) {
          setNum2(num, $(this).find("span").eq(0))
        }
        if (num == 50) {
          setNum3(num, $(this).find("span").eq(0))
        }
        if (num > 50) {
          setNum1(num, $(this).find("span").eq(0))
        }
      })
    } else {
    }
  }

  $(window).on("scroll", triggerNumber)
  triggerNumber()

  function setNum3(num, ele) {
    var nums = 0
    var t = setInterval(function () {
      nums++
      ele.html(nums)
      if (nums == num) {
        clearInterval(t)
      }
    }, 100)
  }

  function setNum2(num, ele) {
    var nums = 0
    var t = setInterval(function () {
      nums++
      ele.html(nums)
      if (nums == num) {
        clearInterval(t)
      }
    }, 300)
  }

  function setNum1(num, ele) {
    var nums = 0
    var t = setInterval(function () {
      nums++
      ele.html(nums)
      if (nums == num) {
        clearInterval(t)
      }
    }, 60)
  }
})